package cn.sharetraffic.mi.servlet;

import cn.sharetraffic.mi.FindListener;
import cn.sharetraffic.mi.etongdai.BaseETDCustomer;
import cn.sharetraffic.mi.listener.SystemListener;
import org.apache.log4j.Logger;
import org.json.JSONObject;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 *
 * 功能：系数设置
 * 作者：蒋睿立
 * 时间：2017/7/25
 * http://www.sharetraffic.cn/mi/setting.jsp
 */
public class SettingServlet extends HttpServlet {

    private Logger log = Logger.getLogger(getClass());
    private StringBuilder sb = new StringBuilder();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        JSONObject json = new JSONObject();
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=UTF-8");
        final java.io.Writer out = resp.getWriter();
        int debt = Integer.parseInt(req.getParameter("debt"));
        int delay = Integer.parseInt(req.getParameter("delay"));
        BaseETDCustomer eTondDai = SystemListener.customerManager.etd[debt];
        FindListener listener = eTondDai.getOnFindListener();
        log.info("设置:"+eTondDai.getClass());
        if(listener != null) {
            listener.setDelayTime(delay);
            json.put("message", "设置成功！");
        }
        else {
            json.put("message", "没找到指定的FindListener");
        }
        out.write(json.toString());
        out.flush();
    }
}
